package com.rfid.db.bean;

import org.greenrobot.greendao.annotation.Entity;

import java.lang.annotation.Retention;
import java.util.Objects;

import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.Transient;

@Entity
public class Rfid {

    @Id(autoincrement = true)
    @Property(nameInDb="id")
    Long id;
    String barcode;//EPC解密后
    String uid;//EPC
    @Property(nameInDb="bookName")
    String bookName;
    String isbn;
    String rindex;
    String shelf;
    @Property(nameInDb="site")
    String site;
    @Property(nameInDb="updateTime")
    String updateTime;

    @Property(nameInDb="originShelf")
    String originShelf;

    int deleted;

    @Transient
    int flag;

    @Transient
    boolean checked;

    public static final int FLAG_DELETE = 8;//服务器删除
    public static final int FLAG_ERR_SHELF = 4;//错架
    public static final int FLAG_FIND = 2;//查找
    public static final int FLAG_CHECKED = 1;//在架
    public static final int FLAG_OK = 0;

    @Generated(hash = 911604178)
    public Rfid(Long id, String barcode, String uid, String bookName, String isbn, String rindex, String shelf, String site,
            String updateTime, String originShelf, int deleted) {
        this.id = id;
        this.barcode = barcode;
        this.uid = uid;
        this.bookName = bookName;
        this.isbn = isbn;
        this.rindex = rindex;
        this.shelf = shelf;
        this.site = site;
        this.updateTime = updateTime;
        this.originShelf = originShelf;
        this.deleted = deleted;
    }

    @Generated(hash = 1126928986)
    public Rfid() {
    }


    @Override
    public String toString() {
        return "Rfid [barcode=" + barcode + ", uid=" + uid + ", bookName=" + bookName + ", isbn=" + isbn + ", index="
                + rindex + ", shelf=" + shelf + ", site=" + site + ", updateTime=" + updateTime + "]";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Rfid rfid = (Rfid) o;
        return Objects.equals(barcode, rfid.barcode) &&
                Objects.equals(bookName, rfid.bookName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(barcode, bookName);
    }

    public static Rfid parser(String rfidStr) {
        if(rfidStr == null || rfidStr.trim().length() == 0) {
            return null;
        }
        String info[] = rfidStr.split(",",-2);
        if(info.length < 8) {
            System.out.println("the Rfid Data is inavail,rfidStr = " + rfidStr);
            StringBuffer sb = new StringBuffer();
            for(String s : info) {
                sb.append(s + "------");
            }
            System.out.println(sb.toString());
            return null;
        }
        Rfid rfid = new Rfid();
        rfid.setBarcode(info[0]);
        rfid.setUid(info[1]);
        rfid.setBookName(info[2]);
        rfid.setIsbn(info[3]);
        rfid.setRindex(info[4]);
        rfid.setShelf(info[5]);
        rfid.setSite(info[6]);
        rfid.setUpdateTime(info[7]);
        return rfid;
    }
    public String getRindex() {
        return this.rindex;
    }
    public void setRindex(String rindex) {
        this.rindex = rindex;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }
    public String getOriginShelf() {
        return this.originShelf;
    }
    public void setOriginShelf(String originShelf) {
        this.originShelf = originShelf;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getId() {
        return this.id;
    }

    public boolean getChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
    public int getDeleted() {
        return this.deleted;
    }
    public void setDeleted(int deleted) {
        this.deleted = deleted;
    }

    public String getBarcode() {
        return this.barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    public String getUid() {
        return this.uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getBookName() {
        return this.bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getIsbn() {
        return this.isbn;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

    public String getShelf() {
        return this.shelf;
    }

    public void setShelf(String shelf) {
        this.shelf = shelf;
    }

    public String getSite() {
        return this.site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
}
